<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

Class Customer_area_model extends CI_Model {

    private $table = "customer_area";
    private $pon_table = "pon";

    function __construct() {
        parent::__construct();
    }

    function insert($data = array()) {
        if ($data != '') {
            $val = array(
                'cm_id' => $data['cm_id'],
                'latitude' => $data['latitude'],
                'longtitude' => $data['longtitude']
            );

            $rs = $this->select_by_filter($val['cm_id']);
            $is = (!empty($rs) && $rs > 0) ? FALSE : ($this->db->insert($this->table, $val) ? TRUE : FALSE);
            return $is;
        }
    }

    function check_insert($val) {
        $rs = $this->db->where('cm_id', $id)->get($this->table);
        $count = $rs->num_rows();
        return $count;
    }

    function select_by_table() {
        $query = $this->db->get($this->table)->result();
        return $query;
    }

    function select_by_filter($id) {
        $rs = $this->db->where('cm_id', $id)->get($this->table)->row_array();
        return $rs;
    }

    function select_by_filter_pon($id) {
        $rs = $this->db->where('pon_id', $id)->get($this->pon_table)->row_array();
        return $rs;
    }

    function update($data = array()) {
        if ($data != '') {
            $val = array(
                'latitude' => $data['latitude'],
                'longtitude' => $data['longtitude']
            );
            ($this->db->where('cm_id', $data['cm_id'])->update($this->table, $val)) ? $is = TRUE : $is = FALSE;
            return $is;
        }
    }

    function delete($data) {
        ($this->db->where('cm_id', $data)->delete($this->table)) ? $is = TRUE : $is = FALSE;
        return $is;
    }

}
